<?php
/**
 * Index.php
 * Niushop商城系统 - 团队十年电商经验汇集巨献!
 * =========================================================
 * Copy right 2015-2025 上海牛之云网络科技有限公司, 保留所有权利。
 * ----------------------------------------------
 * 官方网址: https://www.niushop.com

 * =========================================================
 * @author : niuteam
 * @date : 2015.1.17
 * @version : v1.0.0.0
 */
namespace addon\supermember\api\controller;

use addon\supermember\model\MemberLevelOrder;
use app\api\controller\BaseApi;


/**
 * 会员卡订单
 * @package app\api\controller
 */
class Ordercreate extends BaseApi
{
    /**
     * 订单创建
     * @return false|string
     */
    public function create(){
        $token = $this->checkToken();
        if ($token['code'] < 0) return $this->response($token);

        $data  = [
            'level_id' => $this->params['level_id'],
            //'period_unit' => $this->params['period_unit'],
            'member_id'       => $this->member_id,
            'member_card_type' => isset($this->params['member_card_type']) ? $this->params['member_card_type'] : 1,
        ];

        $order = new MemberLevelOrder();
        $res = $order->create($data);

        return $this->response($res);
    }

    /**
     * Notes:查上级用户
     * User: gai
     * Date: 2023/2/17
     * Time: 18:04
     */
    public function searchParent($member_id,$level){
        $member_info = model('member')->getInfo([['member_id','=',$member_id],['member_level','=',$level]]);

        if ($member_info){
            return $member_info['member_id'];
            /*if ($member_info['member_level']==$level){
                return $member_info['member_id'];
            } else {
                return 0;
            }*/
        } else {
            return $this->searchParent($member_id,$level);
        }
    }
}